cc.Class({
    extends: cc.Component,
    properties: {
        _isAuthUserinfo: !1,
        _systemInfo: null,
        _buttons: null,
        _userInfo: null
    },
    onLoad: function () {
        this._buttons = {}, this.checkAuthUserInfo(), window.authManager = this;
    },
    start: function () {
    },
    getSystemInfo: function () {
        return this._systemInfo || (this._systemInfo = wx.getSystemInfoSync()), this._systemInfo;
    },
    checkAuthUserInfo: function (e) {
        if (tywx.IsWechatPlatform()) try {
            if (this._isAuthUserinfo = !1, this._isAuthUserinfo) return void (e && e(this._isAuthUserinfo));
            var t = this;
            wx.getSetting({
                success: function (n) {
                    n.authSetting["scope.userInfo"] ? (t._isAuthUserinfo = !0, t._userInfo = n) : t._isAuthUserinfo = !1,
                    e && e(t._isAuthUserinfo);
                },
                fail: function (n) {
                    t._isAuthUserinfo = !1, e && e(t._isAuthUserinfo);
                }
            });
        } catch (e) {
            console.error("checkAuthUserInfo error:", e);
        }
    },
    createAuthUserInfoButton: function (e, t, n, o) {
        if (n && e) {
            var i = this._buttons[e];
            i && (i.destroy(), this._buttons[e] = null);
            var a = this;
            this.checkAuthUserInfo(function (i) {
                if (!i) {
                    a.createButton(e, n, o);
                    var r = a._buttons[e];
                    r && (r.sceneShowName = t);
                }
            });
        } else cc.error("createAuthUserInfoButton", "node:" + n + " tag:" + e);
    },
    createButton: function (e, t, n) {
        try {
            var o = this, i = wx.createUserInfoButton({
                type: "image",
                image: "https://szh5.nalrer.cn/szmahjong/WXGames/Shousi/authorizeBtn.png",
                style: {
                    left: 10,
                    top: 76,
                    width: 200,
                    height: 40,
                    lineHeight: 40,
                    backgroundColor: "#ff0000",
                    color: "#ffffff",
                    textAlign: "center",
                    fontSize: 16,
                    borderRadius: 4
                }
            });
            this._buttons[e] = i, i.onTap(function (e) {
                n && e.userInfo && (o._userInfo = e, n(e), o.removeAllButton());
            }), i && t.on("position-changed", function () {
                o.updateUserInfoButton(e, t);
            }), o.updateUserInfoButton(e, t);
        } catch (e) {
            console.error("createButton error:", e);
        }
    },
    updateUserInfoButton: function (e, t) {
        var n = this._buttons[e];
        if (n && cc.isValid(t)) {
            var o = this.getSystemInfo(), i = o.windowWidth / cc.winSize.width,
                a = o.windowHeight / cc.winSize.height;
            n.style.width = t.width * i, n.style.height = t.height * a;
            var r = t.parent.convertToWorldSpaceAR(t.position);
            n.style.left = r.x * i - n.style.width / 2, n.style.top = (cc.winSize.height - r.y) * a - n.style.height / 2;
        }
    },
    removeAllButton: function () {
        for (var e in this._buttons) {
            var t = this._buttons[e];
            t && (t.destroy(), this._buttons[e] = null);
        }
    },
    operateAuthBtnsShow: function (e) {
        for (var t in console.log("operateAuthBtnsShow this._buttons :", this._buttons),
            this._buttons) {
            var n = this._buttons[t];
            n && (console.log("operateAuthBtnsShow isShow:", e, n.sceneShowName, SceneHelper.getCurSceneName()),
                e && n.sceneShowName == SceneHelper.getCurSceneName() ? n.show() : n.hide());
        }
    },
    relogin: function () {
        console.log("========重新把玩家微信信息上传到服务器========="), this._isLogin || (this._isLogin = !0,
            tywx.TuyooSDK.wechatLogin());
    }
})
